package yxy.game.sdk.vivo_quick;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import yxy.apple.http.server.business.BusinessType;
import yxy.apple.logger.Logger;
import yxy.game.bean.LoginOtherParm;
import yxy.game.login.Error;
import yxy.game.login.LoginModule;
import yxy.game.pm2.bean.channel.SdkChannel;
import yxy.game.pm2.bean.cluster.ClusterBean;

@BusinessType(code = "LOGIN")
public class Login extends Sdk_vivo_quick {
	private static final Logger logger = Logger.create(Login.class);

	@Override
	public JSONObject handle(JSONObject request) throws Exception {
		logger.info(SdkChannel.sdk_vivo_quick + ":" + request.toJSONString());

		JSONObject datajson = request.getJSONObject("datajson");
		String playerId = datajson.getString("userId");
		String subchannel = datajson.getString("subchannel");
		String username = playerId;
		String password = playerId;
		String channel = name();
		String ip = request.getString("ip");
		int clusterId = ClusterBean.defaultClusterId;
		if (request.containsKey("clusterId")) {
			clusterId = request.getInteger("clusterId");
		}

		LoginOtherParm loginOtherParm = new LoginOtherParm();
		loginOtherParm.setClusterId(clusterId);

		return new LoginModule().login(username, password, channel, subchannel, ip, loginOtherParm);
	}

	public JSONObject result(JSONObject result, Error errcode) {
		result.put("result", errcode.number());
		return result;
	}

	public static void main(String[] str) {
		String jsonstr = "{\"password\":\"1186143468501532\",\"business\":\"sdk_huawei\",\"ip\":\"/111.163.123.51:28912\",\"datajson\":\"{\\\"uid\\\":\\\"1186143468501532\\\",\\\"userId\\\":\\\"1186143468501532\\\",\\\"userKey\\\":\\\"159******82\\\",\\\"subchannel\\\":\\\"huawei\\\",\\\"userLevel\\\":1,\\\"playerSign\\\":\\\"Y+P+bN2BAdNrLX8DyEglb42wch0PTXIuA/4XpIlJwWU+0nOnq4SPoWAEE7oU+nHoHzCI/6PQCdfzcX4ZF4svDx7MgEqTo6o2lDYqj03wbzxG8yJ8ONc8oCZ0g8/vnZweD4g970UpjVUVf9vIB+xhRRpFEm100Yqz+k4H8DHSk8mzo4YayWOF3rRVhkrBS74/1394AVP+PTb0mHZ0NFNLUwgR5dDMezn/1gMIfjUoYycinXIFk1P7CpoG6QpXBW3VZFuS7XP11x14zPOFdbsrK/ZPZy672iGeuijJIogFvsgw0DafUX2go7pJqJ9N+zO6hYLj1UpMZzmwjv5jJPRqbQ==\\\",\\\"signTs\\\":\\\"1608533736630\\\"}\",\"username\":\"1186143468501532\"}";
		JSONObject json = JSON.parseObject(jsonstr);
		Login login = new Login();
		try {
			login.handle(json);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
